package cn.yh.register.cmn.controller;

import cn.yh.register.cmn.service.DictService;
import cn.yh.register.common.result.Result;
import cn.yh.register.model.cmn.Dict;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
@CrossOrigin //允许跨域访问
@Api(tags = "数据字典接口")
@RestController
@RequestMapping("/admin/cmn/dict")
public class DictController {

    @Autowired
    DictService dictService;

    @ApiOperation("根据id查询子数据")
    @GetMapping("/findChildData/{id}")
    public Result<List<Dict>> findChildData(@PathVariable Long id){
        List<Dict> dictList = dictService.findChildData(id);
        return Result.ok(dictList);
    }

    @ApiOperation("导出数据")
    @GetMapping("/exportData")
    public void exportData(HttpServletResponse response){
        dictService.exportData(response);
    }

    @ApiOperation("导入数据")
    @PostMapping("/importData")
    public void importData(MultipartFile file){
        dictService.importData(file);
    }
}
